package com.fmdj.vhr.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fmdj.common.util.CommonResult;
import com.fmdj.vhr.controller.form.UseVoucherForm;
import com.fmdj.vhr.service.VoucherCustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/voucher/customer")
@Tag(name = "VoucherCustomerController", description = "代金卷模块接口")
@Slf4j
public class VoucherCustomerController {

    @Autowired
    private VoucherCustomerService voucherCustomerService;

    @PostMapping("/userVoucher")
    @Operation(summary = "检查代金卷是否可用")
    public CommonResult userVoucher(@RequestBody @Valid UseVoucherForm form) {
        Map map = BeanUtil.beanToMap(form);
        String discount = voucherCustomerService.userVoucher(map);
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, discount);
    }
}
